<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/comm/comm.jsp"%>
  <script src="${ctx }/static/js/jquery.js" type="text/javascript"></script>
<script type="text/javascript" src="${ctx }/static/js/layer/layer.js"></script>
<link rel="stylesheet" type="text/css" href="${ctx }/static/js/nice-validator/jquery.validator.css">
<div class="row-fluid">
        <div class="span12"> 
          <!-- BEGIN SAMPLE FORM PORTLET-->
          <div class="content-top">
            <div class="portlet-body form"> 
              <!-- BEGIN FORM-->
              <form  id="queryForm"  class="horizontal-form">
                <div class="row-fluid"> 
                  <!--/span-->
                  <div class="span4">
                    <div class="control-group">
                      <label class="control-label" for="">关键字</label>
                      <div class="controls">
                        <input id="keyWord" class="m-wrap span12" placeholder="用户名、姓名、电子邮箱、手机"  value="${keyWord }" type="text">
                        <input type="text" style="display: none">
                      </div>
                    </div>
                  </div>
                  <c:if test="${adminAreas !=null}">
                  <div class="span4">
                    <div class="control-group">
                      <label class="control-label" for="">地区</label>
                      <div class="controls">
                        <select class="m-wrap span12" name="areano" id="areano">
						    <option value="0" >全部</option>
						    <c:forEach items="${adminAreas }" var="item">
										   <option value="${item.areaNo }"  <c:if test="${areano eq item.areaNo}"> selected="selected" </c:if> >${item.areaName }</option>
							</c:forEach>
                        </select>
                      </div>
                    </div>
                  </div>
                  </c:if>
                  <div class="span4">
                    <div class="control-group">
                      <label class="control-label" for="">状态</label>
                      <div class="controls">
                        <select class="m-wrap span12" name="status" id="status">
						    <option value="-1" >全部</option>
						    <option value="1" <c:if test="${status==1 }">selected="selected" </c:if> >启用</option>
						    <option value="0" <c:if test="${status==0 }">selected="selected" </c:if> >禁用</option>
                        </select>
                      </div>
                    </div>
                  </div>
                </div>
                
                <div class="form-actions">
                  <button type="button" class="btn red btn-cent" onclick="queryResult()"  style="width:80px; margin:0 auto;">
                      查询</button>
                  <!-- <button type="button" class="btn blue">导入</button> -->
                </div>
              </form>
              <!-- END FORM--> 
            </div>
          </div>
          <!-- END SAMPLE FORM PORTLET--> 
        </div>
      </div>
      <div class="content-bottom">
        <div class="row-fluid">
          <div class="span12"> 
            <!-- BEGIN EXAMPLE TABLE PORTLET-->
            <div class="portlet box light-grey red" style="border:1px solid #ccc;">
              <div class="portlet-body">
                <div class="clearfix"> </div>
                <div class="portlet-body">
                  <table class="table table-bordered table-hover">
                    <thead>
                      <tr>
                        <th>序号</th>
                        <th>用户名</th>
                        <th>角色</th>
                        <th>姓名</th>
                        <th>电子邮箱</th>
                        <th>手机号码</th>
                        <th>区域</th>
                        <th>状态</th>
                        <th>操作</th>
                      </tr>
                    </thead>
                    <tbody>
                       <c:forEach items="${users }" var="item" varStatus="index">
					    <tr>
							<td>${index.count }</td>
							<td>${item.accountNo }</td>
							<td>${item.roleName }</td>
							<td>${item.userName }</td>
							<td>${item.email }</td>
							<td>${item.tel }</td>
							<td>河南省 ${item.cityName } ${item.countyName }</td>
							<c:if test="${item.isDel ==1 }">
							   <td>启用</td>
							</c:if>
							
							<c:if test="${item.isDel ==0 }">
							   <td>禁用</td>
							</c:if>
							<td class="audit_button">
		                          <a href="javascript:void(0);" class="audit_bj" onclick="display('${item.userId}')">编辑</a>
								  <c:if test="${item.isDel ==0 }">
								     <a href="javascript:void(0);" class="audit_bj" onclick="changeStatus('${item.userId}','1')">启用</a>
								  </c:if>
								  <c:if test="${item.isDel ==1 }">
								     <a href="javascript:void(0);" class="audit_bj" onclick="changeStatus('${item.userId}','0')">禁用</a>
								  </c:if>
								  <a href="javascript:void(0);" class="audit_bj" onclick="resetPwd('${item.userId}')">重置密码</a>
		                    </td>
						</tr>
				      </c:forEach>
                    </tbody>
                  </table>
                </div>
                <div class="row-fluid">
			        <div class="span6"></div>
					<div class="span6">
						<%@ include file="/WEB-INF/pages/comm/page.jsp" %>
					</div>
				</div>
              </div>
            </div>
            
            <!-- END EXAMPLE TABLE PORTLET--> 
            
          </div>
        </div>
</div>
<input type="hidden" id="pageNo" name="pageNo" value='${page.pageNo }'>

<!-- END PAGE -->
<script type="text/javascript">

function changeStatus(userId,status){

 $.ajax({
    		url: '${ctx}'+'/user/status',
    		type: 'post',
    		dataType: 'json',
    		data: {
    		   "userId":userId,
    		   "status":status
    		},
    		success: function (data) {
    		    if(data.code==200){
    		      if(status == 1){
    		        layer.msg("启用成功");
    		      }else{
    		        layer.msg("禁用成功");
    		      }
    			}else{
    			  layer.msg(data.msg);
    			}
    			queryResult();
    		}
    });
}

function queryResult(){
   
   var keyWord= $("#keyWord").val();
   var status = $("#status option:selected") .val();
   var areano = $("#areano option:selected") .val();
   if(status=="undefined"){
   	 status=null;
   }
   var pageNo = $("#pageNo").val();
   var datas={
              "keyWord":keyWord,
              "status":status,
              areano:areano,
              "pageNo":pageNo
    		};
   $.ajax({
    		url: '${ctx}'+'/user/managerList',
    		type: 'post',
    		dataType: 'html',
    		data: datas,
    		success: function (data) {
    		    $("#main").html(data);
    		}
    });
}

function resetPwd(userId){
layer.confirm('确定要重置该记录？', {
			btn: ['确定','取消']
		}, function() {
			$.ajax({
	    		url: '${ctx}'+'/user/resetPwd',
	    		type: 'post',
	    		dataType: 'json',
	    		data: {
	              "userId":userId
	    		},
	    		success: function (data) {
	    		  if(data.code==200){
	    			  layer.msg("重置成功，密码：123456");
	    			}else{
	    			  layer.msg(data.msg);
	    			}
	    		}
    });
  });
}
function display(userId) {
   
   layer.open({
		title: '更新用户',
		type: 2,
		skin: 'layui-layer-rim', //加上边框
		area: ['70%', '510px'], //宽高
		content: '${ctx}' +'/user/userDetais/'+userId+'/1'
	});
	
}
</script>
